#include <REGX52.H>

unsigned char  code SMG[18] =	{0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e,0xbf,0x7f};

	
unsigned char yue = 0;
	
void SelectHC573(unsigned char n)
{

		switch(n)
	{
		case 4:
			P2 = (P2 & 0x1f) | 0x80;
			break;
		case 5:
			P2 = (P2 & 0x1f) | 0xa0;
			break;
		case 6:
			P2 = (P2 & 0x1f) | 0xc0;
			break;
		case 7:
			P2 = (P2 & 0x1f) | 0xe0;	
			break;
	}	
}

void DisplaySMG(unsigned char value,unsigned char pos)
{
	SelectHC573(6);
	P0 = 0x01 << pos;
	SelectHC573(7);
	P0 = value;
}

void DelaySMG(unsigned int t)
{
	while(t--);

}


void Display_active()
{
		DisplaySMG(SMG[2],0);
		DelaySMG(500);
		DisplaySMG(SMG[0],1);
		DelaySMG(500);
		DisplaySMG(SMG[1],2);
		DelaySMG(500);	
		DisplaySMG(SMG[8],3);
		DelaySMG(500);
		DisplaySMG(SMG[16],4);
		DelaySMG(500);
		DisplaySMG(SMG[16],5);
		DelaySMG(500);
		DisplaySMG(SMG[yue / 10],6);
		DelaySMG(500);
		DisplaySMG(SMG[yue % 10],7);
		DelaySMG(500);
}

void DelayABC(unsigned int t)
{
	while(t--)
	{
		Display_active();
	}
}

void main()
{
	while(1)
	{
		Display_active();
		yue++;
		if(yue > 12)
		{
			yue = 0;
		}
		DelayABC(300);
	}
		
}